package com.whmskj.xjlhbc.mobile.controller;

import com.whmskj.xjlhbc.core.AjaxResult;
import com.whmskj.xjlhbc.domain.Bcry12zbgghgl;
import com.whmskj.xjlhbc.domain.PersonnelManagementDataSheets;
import com.whmskj.xjlhbc.service.IBcry12zbgghglService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 织布工工号管理Controller
 */
@Tag(name = "织布工工号管理", description = "织布工工号管理相关接口")
@RestController
@RequestMapping("/mobile/weaver")
public class WeaverController {

    @Autowired
    private IBcry12zbgghglService bcry12zbgghglService;


    /**
     * 只返回姓名列表（class22 等值匹配）
     */
    @Operation(summary = "获取指定班别的姓名列表", description = "class22 等值匹配：织布甲班/织布乙班")
    @GetMapping("/getPersonnelNamesByClass")
    public AjaxResult getPersonnelNamesByClass(
            @Parameter(description = "班别（必须为：织布甲班 / 织布乙班）", required = true) @RequestParam String classType) {
        try {
            return AjaxResult.success("查询成功", bcry12zbgghglService.getPersonnelNamesByClass(classType));
        } catch (Exception e) {
            return AjaxResult.error("查询失败：" + e.getMessage());
        }
    }


    /**
     * 获取织布工列表（根据班别）
     */
    @Operation(summary = "获取织布工列表", description = "根据班别获取织布工列表，前端传甲或乙")
    @GetMapping("/getWeaverList")
    public AjaxResult getWeaverList(
            @Parameter(description = "班别（甲/乙）", required = true) @RequestParam String classType) {
        try {
            // 将前端传的"甲"/"乙"转换为"甲班"/"乙班"
            String ben = "甲".equals(classType) ? "甲班" : "乙".equals(classType) ? "乙班" : classType;
            List<Bcry12zbgghgl> list = bcry12zbgghglService.getWeaverListByClass(ben);
            return AjaxResult.success("查询成功", list);
        } catch (Exception e) {
            return AjaxResult.error("查询失败：" + e.getMessage());
        }
    }

    /**
     * 修改挡车工姓名（点击某条工号后，根据选择的姓名进行更新）
     */
    @Operation(summary = "修改挡车工姓名", description = "根据工号更新挡车工姓名，姓名来自 getPersonnelNamesByClass")
    @PostMapping("/updateDriverNameById")
    public AjaxResult updateDriverNameById(
            @Parameter(description = "主键ID", required = true) @RequestParam Long id,
            @Parameter(description = "挡车工姓名", required = true) @RequestParam String nameyee) {
        return bcry12zbgghglService.updateDriverNameById(id, nameyee);
    }
}
